package tp1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

class SocketHandler extends Thread {
	Socket client;

	SocketHandler(Socket client) {
		this.client = client;
	}

	public void run() {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					client.getInputStream()));
			PrintStream out = new PrintStream(client.getOutputStream());
			boolean done = false;
			while (!done) {
				String str = reader.readLine();
				if (str == null)
					done = true;
				else {
					out.println("Echo: " + str);
					if (str.trim().equals("BYE"))
						done = true;
				}
			}
			client.close();
			System.out.println("BYE-BYE");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


